var applyCashTable;
//var roleid = document
//.getElementById("roleid").value;
//if (roleid == "0") {
//	document.getElementById("actions").style.visibility = "hidden";// 隐藏
//}
function getapplyCashList() {
	if (typeof applyCashTable !== 'undefined') {
		applyCashTable.fnPageChange('first');
		return;
	}
	var i = 1;
	applyCashTable = $("#applyCashList")
			.DataTable(
					{
						"sAjaxSource" : _path + "/applyCash/queryByPage",
						"fnServerParams" : function(aoData) {
							aoData.push({
								"name" : "userNickName",
								"value" : $("#userNickName").val()
							},
							{
								"name" : "status",
								"value" : $("#status").val()
							},{
								"name" : "fromDate",
								"value" : $("#fromDate").val()
							}, {
								"name" : "toDate",
								"value" : $("#toDate").val()
							});
						},
						"sServerMethod" : "POST",
						"sAjaxDataProp" : "dataList",
						"fnCreatedRow" : function() {
							i++;
						},
						"fnPreDrawCallback" : function() {
							i = 1;
						},
						"aoColumns" : [
								{
									"sTitle" : "序号",
									"sWidth" : "2%",
									"mData" : function() {
										return i;
									}
								},
								{
									"sTitle" : "用户唯一id",
									"mData" : "userOpenId",
									"sWidth" : "10%"
								},
								{
									"sTitle" : "用户昵称",
									"mData" : "userNickName",
									"sWidth" : "10%"
								},	{
									"sTitle" : "开户行",
									"mData" : "smh",
									"sWidth" : "10%"
								},
								{
									"sTitle" : "提取人名字",
									"mData" : "cardname",
									"sWidth" : "10%"
								},{
									"sTitle" : "银行卡",
									"mData" : "cardnumber",
									"sWidth" : "10%"
								},
								{
									"sTitle" : "申请提现金额",
									"mData" : "applyCash",
									"sWidth" : "10%"
								},
								{
									"sTitle" : "余额",
									"mData" : "total",
									"sWidth" : "10%"
								},
								{
									"sTitle" : "状态",
									"mData" : "status",
									"sWidth" : "10%",
									"mRender" : function(data) {
										var status = '';
										switch (data) {
										case '0':
											status = '未提现';
											break;
										case '1':
											status = '未打款';
											break;
										case '2':
											status = '已打款';
											break;
										case '3':
											status = '提现失败';
											break;
										default:
											status = '未知';
											break;
										}
										return status;
									}
								},
								{
									"sTitle" : "申请时间",
									"mData" : "createTime",
									"sWidth" : "10%"
								},
								{
									"sTitle" : "操作",
									"sWidth" : "10%",
									"mData" : function(data) {
										var status = '<a href="'
												+ _path
												+ '/applyCash/edit/'
												+ data.id
												+ '" class="btn default btn-xs purple"><i class="fa fa-edit" title="编辑"></i></a>';
										var	status = '&#8197<select id="select'+data.id+'" name="select" onchange="advertising('+ data.id+')" style="height:21px" class="btn default btn-xs purple"><option value="" selected="selected">操作</option><option value="2">申请通过</option><option value="3">申请失败</option></select>';
				
									
									return status;
								}
							} 
								]
					});
}
function inquiry(id) {

	layer.confirm('您确定要删除吗？', {
		btn : [ '确定', '取消' ]
	// 按钮
	}, function() {
		location.href = _path + "/applyCash/del/" + id;
	}, function() {

	});
}

//下拉列表选项操作
function advertising(id){
	var i=$("#select"+id).val();                          //获取选中的value的值
	var s=$("#select"+id).find("option:selected").text(); //获取选中文本域的值
	if(i=='2'||i=='3'){
		$.ajax({
		       cache: true,
		       type: "POST",
		       url:_path+"/applyCash/statusSwitch?id="+id+"&status="+i,
		       async: false,
		       dataType : "json",
		       error: function(request) {
		    	   alert("连接错误！");
		       },
		       success: function(data) {
		    	   layer.alert(s, {
		  		        icon: 1,
		  		        offset: 'middle',
		  		        time: 2000, 
		  		        skin: 'layui-layer-lan'
		  		   });
		    	   setTimeout("Refresh()",2000);
	           }
	    })
	}
}
//对当前页面进行刷新
function Refresh(){
	location.reload();
}

